Using wget
or curl
commands to retrieve remote content in Dockerfiles instead of the ADD
instruction can
lead to several issues, particularly related to the inefficient use of Docker’s build cache.
Docker’s build cache is a powerful feature that can significantly speed up the build process by reusing intermediate layers from previous builds if
no changes were detected. When you use wget
, curl
, or similar commands, these commands are run during the build process, and
Docker has no way of knowing if the remote content has changed without executing the commands. This makes it impossible to cache the results of these
commands efficiently.
Moreover, installing third-party tools inside the image can introduce unnecessary complexity, dependency on external tools and increase the size of
the final image.
Exceptions
In some cases, the ADD
instruction is not able to replace the wget
or curl
command, especially if specific
HTTP parameters are required: method, headers, body, etc.
FROM ubuntu:20.04
RUN wget --header="Authorization: Bearer your_token" --method=POST https://example.com/resource